#!/usr/bin/python
# -*- coding: UTF-8 -*-

from django.http import HttpResponse
import json
from local.result import Result


def hello(request):
    print("***", request)
    return HttpResponse(
        Result.success("hello world!", {}).json(),
        content_type='application/json'
    )


def get(request):
    "GET请求"
    print("****", request)
    params = request.GET
    print("***", params)
    if "q" in params:
        print("***", params["q"])
    else:
        print("空表单".decode('UTF-8'))
    return HttpResponse(
        Result.success1().json(),
        content_type='application/json'
    )


def post(request):
    "POST Form请求"
    print("****", request)
    params = request.POST
    print("***", params)
    if "q" in params:
        print("***", params["q"])
    else:
        print("空表单".decode('UTF-8'))
    return HttpResponse(
        Result.success1().json(),
        content_type='application/json'
    )


def post_json(request):
    "POST Json请求"
    print("****", request)
    params = request.body
    print("***", params)
    obj = json.loads(params)
    print("***", obj)
    return HttpResponse(
        Result.success1().json(),
        content_type='application/json'
    )


